-module(err).
-export([errsig/0]).

errsig() ->
    spawn_link(fun() -> loop() end),
    receive
    after
        %1000  ->  throw({myerror, abc})
        %1000  ->  catch exit({myerror, abc})
        1000  ->  try erlang:error({myerror, abc})
                catch
                    error:X -> {caught, X}
                end
    end.

loop() ->
    io:format("loop start~n"),
    process_flag(trap_exit, true),
    receive
        {'EXIT', Pid, Why} ->
            io:format("receive error ~p from ~p~n", [Why, Pid])
    after 
        5000 ->
            io:format("loop end~n")
    end.
